# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
#
# 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
#
# 
# @param head ListNode类 
# @return ListNode类
#
class Solution:
    def remove_duplicate(self , head ):
        # write code here
        _head = head
        mmap = {}
        while _head is not None:
            if _head.val not in mmap:
                mmap[_head.val] = 1
            else:
                mmap[_head.val] +=1
            _head = _head.next
        
        # 处理链表头
        while mmap[head.val] > 1:
            head = head.next
        
        pre = head
        cur = head.next
        next_ = head.next.next
        while(next_ is not None):
            if mmap[cur.val] > 1:
                #删除节点
                temp = next_
                pre.next = temp
            pre = pre.next
            cur = cur.next
            next_ = next_.next
        return head
                